odoo.define('sys.main_to_item_view', function (require) {
    "use strict";
    var ListController = require('web.ListController');
    var ListView = require('web.ListView');
    var Session = require('web.session');
    var viewRegistry = require('web.view_registry');
    var FormView = require('web.FormView');
    var ListRenderer = require('web.ListRenderer');
    var core = require('web.core');
    var OpenListController = ListController.extend({
        _onOpenRecord: function (ev) {
            ev.stopPropagation();
            var originalFormId = null;
            var record = this.model.get(ev.data.id, {raw: true});
            _.each(this.actionViews, function (item) {
                if (item.type === 'form') {
                    originalFormId = item.viewID;
                }

            });
            this.renderer.openRecord(this.modelName, record.res_id, originalFormId, this.viewId);
        },
    });
    var OpenListRenderer = ListRenderer.extend({
        openRecord: function (model, res_id, form_id, tree_id) {
            var self = this;
            if (model === "agripro.pro_product_output_employees") {
                return this._rpc({
                    model: 'agripro.pro_product_output_employees',
                    method: 'jump_form_view',
                    args: [res_id],
                }).then(function (result) {
                    self.do_action(result)
                });
            }
            if(model === "agripro.pro_product_output"){
               return this._rpc({
                    model: 'agripro.pro_product_output',
                method: 'jump_form_view',
                args: [res_id,form_id, tree_id],
            }).then(function (result) {
                self.do_action(result)
            });
            }
            //

        },
    });


    var CustomListView = ListView.extend({
        config: _.extend({}, ListView.prototype.config, {
            Controller: OpenListController,
            Renderer: OpenListRenderer,
        }),
    });
    viewRegistry.add('sys_main_to_item_view', CustomListView);
});